package es.udima.geo.geoserver.entities;

import java.io.Serializable;
import java.util.Calendar;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

@Entity
@Table(name = "userGpsData")
@IdClass(value = GpsDataPK.class)
public class GpsData implements Comparable<GpsData>, Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    private String userId;
    @Id
    @Temporal(TemporalType.TIMESTAMP)
    private Calendar fetchTime;
    private double lat;
    private double lon;
    
    @Transient
    private double distanceFromPrevious; // distance from a previous point in
					 // meters
    @Transient
    private double lapseTimeFromPrevious; // time from a previous point in
					  // milliseconds
    @Transient
    private double speedFromPrevious; // average speed from a previous point in
				      // km/h

    public GpsData() {

    }

    public GpsData(String userId, Calendar fetchTime, double lat, double lon) {
	this.userId = userId;
	this.fetchTime = fetchTime;
	this.lat = lat;
	this.lon = lon;
    }

    public String getUserId() {
	return userId;
    }

    public void setUserId(String userId) {
	this.userId = userId;
    }

    public Calendar getFetchTime() {
	return fetchTime;
    }

    public void setFetchTime(Calendar fetchTime) {
	this.fetchTime = fetchTime;
    }

    public double getLat() {
	return lat;
    }

    public void setLat(double lat) {
	this.lat = lat;
    }

    public double getLon() {
	return lon;
    }

    public void setLon(double lon) {
	this.lon = lon;
    }

    public double getDistanceFromPrevious() {
	return distanceFromPrevious;
    }

    public void setDistanceFromPrevious(double distanceFromPrevious) {
	this.distanceFromPrevious = distanceFromPrevious;
    }

    public double getLapseTimeFromPrevious() {
	return lapseTimeFromPrevious;
    }

    public void setLapseTimeFromPrevious(double lapseTimeFromPrevious) {
	this.lapseTimeFromPrevious = lapseTimeFromPrevious;
    }

    public double getSpeedFromPrevious() {
	return speedFromPrevious;
    }

    public void setSpeedFromPrevious(double speedFromPrevious) {
	this.speedFromPrevious = speedFromPrevious;
    }

    @Override
    public String toString() {
	return "GpsData [userId=" + userId + ", fetchTime=" + fetchTime + ", lat=" + lat + ", lon=" + lon + ", distanceFromPrevious="
		+ distanceFromPrevious + ", lapseTimeFromPrevious=" + lapseTimeFromPrevious + ", speedFromPrevious=" + speedFromPrevious + "]";
    }

    @Override
    public int compareTo(GpsData o) {
	int res = this.getUserId().compareTo(o.getUserId());
	if (res == 0) {
	    res = this.getFetchTime().compareTo(o.getFetchTime());
	}
	return res;
    }
}
